/**
 * Created by Administrator on 2017/4/23 0023.
 */
//跳转方法
function hrefgo(e){
    var url= e.dataset.href;
    var pageid=e.dataset.page;
    var euserid=e.dataset.euser;
    var eid=url.match(/[0-9]+/)[0];

    $.cookie("pulupagescroll",$(window).scrollTop());//当前滚动距离
    $.cookie("pulupagepage",pageid);//当前显示页面
    $.cookie("jycurrentIndex",jycurrentIndex);//经验 铺路数据页码
    //清除转发者信息 防止返回信息保存
    $.cookie("shareUserId","");
    $.cookie("fromuser","");
    if(e.dataset.shareuserid){
        //shareuser="&shareuser="+e.dataset.shareuserid;
        $.cookie("shareUserId",e.dataset.shareuserid);
    }
    location.href=url;
}
//发高额
function gotoheiexp(data){
    var eid=data.dataset.keyword;
    var e=arguments.callee.caller.arguments[0]||event;
    var loca=location.href;
    if(e&&e.stopPropagation()){
        e.stopPropagation();
    }else if(window.event){
        window.event.cancelBubble = true;
    }
    //$.cookie("expkeyword",eid);
    //$.cookie("expType","");
    //$.cookie("sendque","");
    ///questionchikui/.test(loca)?$.cookie("expType","chikui"):/questionhuasuan/.test(loca)?$.cookie("expType","huasuan"):/questionxinqi/.test(loca)?$.cookie("expType","xinqi"):/questiondianying/.test(loca)?$.cookie("expType","tuijiandy"):/questionfandian/.test(loca)?$.cookie("expType","tuijianfd"):/questionyouwan/.test(loca)?$.cookie("expType","youwan"):/questionshu/.test(loca)?$.cookie("expType","shu"):/questionqita/.test(loca)?$.cookie("expType","qita"):$.cookie("expType","");
    //location.href="http://www.pulu.com/weixin/sendexpgpc.html";
    if(is_weixn()){
        $.cookie("expkeyword",eid);
        $.cookie("expType","");
        $.cookie("sendque","");
        /questionchikui/.test(loca)?$.cookie("expType","chikui"):/questionhuasuan/.test(loca)?$.cookie("expType","huasuan"):/questionxinqi/.test(loca)?$.cookie("expType","xinqi"):/questiondianying/.test(loca)?$.cookie("expType","tuijiandy"):/questionfandian/.test(loca)?$.cookie("expType","tuijianfd"):/questionyouwan/.test(loca)?$.cookie("expType","youwan"):/questionshu/.test(loca)?$.cookie("expType","shu"):/questionqita/.test(loca)?$.cookie("expType","qita"):/questionjk/.test(loca)?$.cookie("expType","jkjy"):/questiongw/.test(loca)?$.cookie("expType","gwjy"):/questiongz/.test(loca)?$.cookie("expType","gzjy"):/questionye/.test(loca)?$.cookie("expType","yejy"):$.cookie("expType","");
        location.href="http://www.pulu.com/weixin/sendexpgpc.html";
    }
    else{
        var expType="";
        /questionchikui/.test(loca)?expType="&expType=chikui":/questionhuasuan/.test(loca)?expType="&expType=huasuan":/questionxinqi/.test(loca)?expType="&expType=xinqi":/questiondianying/.test(loca)?expType="&expType=tuijiandy":/questionfandian/.test(loca)?expType="&expType=tuijianfd":/questionyouwan/.test(loca)?expType="&expType=youwan":/questionshu/.test(loca)?expType="&expType=shu":/questionqita/.test(loca)?expType="&expType=qita":/questionye/.test(loca)?expType="&expType=yejy":/questiongz/.test(loca)?expType="&expType=gzjy":/questiongw/.test(loca)?expType="&expType=gwjy":/questionjk/.test(loca)?expType="&expType=jkjy":expType="";
        location.href="https://www.pulu.com/weixin/sendexpgpc.html?id="+id+"&keyword="+eid+expType;
    }
}
//展示加载图片
function showloadimg(e){
    $(e).fadeIn();
}
function gohrefftnerr(){
    var e=arguments.callee.caller.arguments[0]||event; //若省略此句，下面的e改为event，IE运行可以，但是其他浏览器就不兼容
    if ( e && e.stopPropagation ) {
        // 因此它支持W3C的stopPropagation()方法
        e.stopPropagation();
    } else {
        // 否则，我们需要使用IE的方式来取消事件冒泡
        window.event.cancelBubble = true;
    }
}
var jyhaveajax=false;
function jy(ajurl,jycurrentIndex,pageSize,isheigh){
    //全部经验页 返回家在重复使用jyhaveajax进行判断 pulupagejy.js
    if(!jyhaveajax&&jycurrentIndex!=1){ //没有发起过请求 并且页码不是1
        jycurrentIndex=1;
        jyhaveajax=true;
    }
    else{
        if(jyover===0){
            jyhaveajax=true;
            $.ajax({
                type:"get",
                datatype:"json",
                url:ajurl+"?userId="+id+"&currentIndex="+jycurrentIndex+"&pageSize="+pageSize+isheigh,
                success:function(d){
                    var ulid="#explist";
                    if(d.Message==="没有数据"||(d.Data&&d.Data.length===0)||!d.Data){
                        jyover=1;
                        readyover=0;
                        $("#waiting1").css("display","none");
                        $("#nonews1").css("display","block");
                    }else{
                        if(d.Data.length<pageSize){
                            //$("#waiting1").remove();
                            $("#waiting1").css("display","none");
                            $("#nonews1").css("display","block");
                        }
                        var fortime=0;//循环次数
                        for(var i= 0,r=d.Data.length;i<r ;i++){
                            fortime++;
                            d.Data[i].index=i;
                            if(d.Data[i].title&&d.Data[i].title.length>0){
                                //匿名
                                var unick="";
                                if(d.Data[i].questionUserNick){
                                    if(d.Data[i].ishidename==1){
                                        unick="<a>匿名</a>";
                                    }else{
                                        unick="<a href='http://www.pulu.com/weixin/otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].nick+"</a>";
                                    }
                                }
                                //头像
                                var uimgword="";
                                if(d.Data[i].questionUserAva){
                                    if(d.Data[i].ishidename==1){
                                        uimgword="<a href='javascript: ;'><img onclick='gohrefftnerr(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)'></a>";
                                    }else{
                                        uimgword="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+d.Data[i].questionUserAva+"' onload='showloadimg(this)' style='display:none;'></a>";
                                    }
                                }else{
                                    if(d.Data[i].ishidename==1){
                                        uimgword="<a href='javascript: ;'><img onclick='gohrefftnerr(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                                    }else{
                                        uimgword="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'><img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                                    }
                                    //uimgword="<img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png'>";
                                };
                                var otherid=d.Data[i].userId;
                                //时间
                                var tim="";
                                if(d.Data[i].ctime){
                                    tim=getDateDiff(getDateTimeStamp(d.Data[i].ctime));
                                }
                                var testtime=getDateTimeStamp(d.Data[i].ctime);
                                //有没有图片
                                var haveimg="";
                                if(d.Data[i].imgcount>0){
                                    haveimg="<span class='isheighlogo haveimg'></span>"
                                }
                                //if(d.Data[i].imgcount>0){
                                //    haveimg="(图)"
                                //}
                                //是不是推荐
                                var tuijianword="";
                                var moneysty='style="position:absolute;right:0;"';
                                if(d.Data[i].isStranger===1){
                                    tuijianword="<div class='tuijian'></div>";
                                    moneysty='style="position:absolute;right:64px;"';
                                }
                                //有没有钱
                                var money="";
                                if(d.Data[i].score>0){
                                    var score= parseFloat(d.Data[i].score)/100;
                                    money="<span class='havemy' "+moneysty+">¥ "+score+"</span>";
                                }
                                //是不是转换
                                var isconvert="";
                                if(d.Data[i].isconvert&&d.Data[i].isconvert===1){
                                    isconvert="(悬赏完成转经验)"
                                }
                                //判断是否有点赞者
                                var userimg="";//保存头像代码段 修改评星
                                //评星
                                var starlen=0;
                                if(d.Data[i].star!==0){
                                    var strnum=(d.Data[i].star).toString();
                                    if(strnum.length===3){
                                        var lastnum=parseFloat(strnum.substring(strnum.length-1));
                                        //尾数在4~6之间
                                        if(lastnum>=4&&lastnum<=6){
                                            starlen=strnum.substring(strnum.length-1,0)+5;
                                        }else if(lastnum<4){
                                            starlen=strnum.substring(0,1);
                                        }else if(lastnum>6){
                                            starlen=parseFloat(strnum.substring(0,1))+1;
                                        }
                                    }else{
                                        starlen=d.Data[i].star;
                                    }

                                }
                                userimg="<div class='starimg'><i style='width:"+parseFloat(starlen)*20+"%;'></i></div>";
                                //我也说说
                                var gotoheiexp="<div class='gotoheiexp' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+">我也来说说：有关</div>";
                                //高额
                                var isheilogo="";
                                if(d.Data[i].isexphigh===1||d.Data[i].isexphigh===2){
                                    isheilogo="<span class='isheighlogo'></span>";
                                }
                                //标题
                                //var tit=codetoface(d.Data[i].title)+"(还有"+d.Data[i].wordcount+"字)";
                                var tit=codetoface(d.Data[i].title);
                                var count=0;
                                if(d.Data[i].count){
                                    count=d.Data[i].count;
                                }
                                //昵称
                                var unick="";
                                if(d.Data[i].ishidename===1){
                                    unick="<a>匿名</a>";
                                }else{
                                    unick="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].questionUserNick+"</a>";
                                }
                                //位置
                                var location="";
                                if(d.Data[i].pululocation){
                                    location="<div style='position:relative;'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:2px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.Data[i].pululocation+"</span></div>"
                                }
                                //关键词
                                var keywordnor;
                                var keyword="<span class='keywordtit' style='display:none;'>关键词：</span>";
                                if(d.Data[i].keywords){
                                    keywordnor=d.Data[i].keywords.split(",");
                                    for(var a=0;a<keywordnor.length;a++){
                                        keyword+="<span>"+keywordnor[a]+"</span>";
                                    }
                                }
                                if(!d.Data[i].shareUserId){
                                    if(!tim){
                                        tim="刚刚";
                                    }
                                    $("#explist .addlistplace").append("<div class='pagedlist_item shareexperience' data-money='"+d.Data[i].score+"' onclick='hrefgo(this)' data-page='"+ulid+"' data-isheight='"+d.Data[i].isexphigh+"' data-euser='"+d.Data[i].questionUserId+"' data-href='http://www.pulu.com/weixin/shareexppage.html?eid="+d.Data[i].id+"#fromuser="+id+"'><div class='feed_item feed_type_question'>"+tuijianword+"<div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+isheilogo+"</span><div class='ContentFooter'>"+tim+"</div></div></div></div>"+"<h2><a class='question_link'>"+isconvert+tit+"("+d.Data[i].wordcount+"字)"+haveimg+"</a></h2><div class='upviter'>"+userimg+"</div><div class='ActionBar Question'>"+location+"<div class='action_bar_inner'><div class='action_item'> <a class='ReadMoreActionItem'>浏览 "+count+"&nbsp;&nbsp;&nbsp;付费 "+d.Data[i].payCount+"</a> </div> </div></div>"+"<div class='question_topics_container' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+"><div class='QuestionTopics has_topics'>"+gotoheiexp+keyword+"</div></div></div></div>");

                                }
                                //转发
                                else if(d.Data[i].shareUserId&&d.Data[i].shareUserId.length>0){
                                    var des="";
                                    if(d.Data[i].des){
                                        des=codetoface(d.Data[i].des);
                                    }
                                    var count=0;
                                    if(d.Data[i].count){
                                        count=d.Data[i].count;
                                    }
                                    var sharetim=getDateDiff(getDateTimeStamp(d.Data[i].shareTime.match(/[0-9\-T\:]+/)[0]));
                                    var tim=getDateDiff(getDateTimeStamp(d.Data[i].ctime.match(/[0-9\-T\:]+/)[0]));
                                    var unick="";
                                    if(d.Data[i].ishidename===1){
                                        unick="<a>匿名</a>";
                                    }else{
                                        unick="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].questionUserNick+"</a>";
                                    }
                                    var location="";
                                    if(d.Data[i].pululocation){
                                        location="<div style='position:relative;'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:2px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.Data[i].pululocation+"</span></div>"
                                    }
                                    //转发调整金额样式
                                    var moneysty='style="position:absolute;right:0;"';
                                    money="<span class='havemy' "+moneysty+">¥ "+score+"</span>";
                                    if(!sharetim){
                                        sharetim="刚刚";
                                    }
                                    var  peopleurl="'otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'";
                                    $("#explist .addlistplace").append("<div class='pagedlist_item shareexperience' data-money='"+d.Data[i].score+"' onclick='hrefgo(this)' data-page='"+ulid+"' data-isheight='"+d.Data[i].isexphigh+"' data-euser='"+d.Data[i].questionUserId+"' data-href='http://www.pulu.com/weixin/shareexppage.html?eid="+d.Data[i].id+"#fromuser="+id+"' data-shareuserid='"+d.Data[i].shareUserId+"'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+ d.Data[i].shareUserNick+"·转发</span>·"+sharetim+"</div><div class='info_wrapper' style='margin-left:10px;margin-top:7px;'> <div class='info'> <span class='feed_item_answer_user'>"+des+"</span> </div> </div> <div class='borderbox'><div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+isheilogo+"</span> <div class='ContentFooter'>"+tim+"</div></div></div></div>"+"<h2><a class='question_link'>"+isconvert+tit+"("+d.Data[i].wordcount+"字)"+haveimg+"</a></h2><div class='upviter'>"+userimg+"</div><div class='ActionBar Question'>"+location+"<div class='action_bar_inner'><div class='action_item'> <a class='ReadMoreActionItem'>浏览 "+count+"&nbsp;&nbsp;&nbsp;付费 "+d.Data[i].payCount+"</a> </div></div></div>"+"<div class='question_topics_container' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+"><div class='QuestionTopics has_topics'>"+gotoheiexp+keyword+"</div></div></div></div></div>")
                                }
                            };
                            //页面滚动判断
                            if("#explist"===$.cookie("pulupagepage")&&fortime===r&&$.cookie("pulupagescroll")&&parseFloat($.cookie("pulupagescroll"))>0){
                                $(window).scrollTop(parseFloat($.cookie("pulupagescroll")));
                                readyover=0;
                                $.cookie("pulupagepage","");//清除页面ID
                                $.cookie("pulupagescroll","");//当前滚动距离
                                $.cookie("pulupagepage","");//当前显示页面
                                $.cookie("tjcurrentIndex","");//推荐数据页码
                                $.cookie("zhncurrentIndex","");//召唤你数据页码
                                $.cookie("jycurrentIndex","");//经验 铺路数据页码
                            };
                            if(fortime==r){
                                readyover=0;
                            }
                        };
                    }
                }
            })
        };
    }
}